<?

include_once "conn.php";

if($_POST[credit_card_processed] == 'Y')
{
	$array = explode("|", $_POST[cart_order_id]);

	$PlanName = $array[0];
	$payename = $array[2];
	$user_type = $array[3];

	if($user_type == "e")
	{
		$q = "select * from job_plan where PlanID = '$PlanName' ";
		$r = mysql_query($q) or die(mysql_error());
		$a = mysql_fetch_array($r);

		$q1 = "update job_employer_info set plan = '$a[PlanName]', JS_number = '$a[reviews]', JP_number = '$a[postings]' where ename = '$payename' ";
		mysql_query($q1) or die(mysql_error());

		$qm = "select CompanyEmail from job_employer_info where ename = '$payename' ";
		$rqm = mysql_query($qm) or die(mysql_error());
		$am = mysql_fetch_array($rqm);

		$to = $am[0];
		$subject = "Your employer plan at $_SERVER[HTTP_HOST]";
		$message = "Hello,\nhere is your employer plan information at $_SERVER[HTTP_HOST]:\n\nPlan name: $a[PlanName]\nNumber of resume viewing: $a[reviews]\nNumber of Job Offer postings: $a[postings]\n\n$_SERVER[HTTP_HOST]";
		$from = "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>";

		mail($to, $subject, $message, $from);
		header("location:employers/thanks.php");
		exit();
	}
	else
	{
		//get the price info
		$q1 = "select * from job_prices where PriceID = '$PlanName' ";
		$r1 = mysql_query($q1) or die(mysql_error());
		$a1 = mysql_fetch_array($r1);

		$p = mktime(0,0,0,date(m) + $a1[months], date(d), date(Y));

		$q2 = "update job_seeker_info set paid = '$p' where uname = '$payename' ";
		mysql_query($q2) or die(mysql_error());

		//get the user info
		$q3 = "select * from job_seeker_info where uname = '$payename' ";
		$r3 = mysql_query($q3) or die(mysql_error());
		$a3 = mysql_fetch_array($r3);

		//send an email
		$to = $a3[job_seeker_email];
		$subject = "Your registration at $_SERVER[HTTP_HOST]";
		$message_body = "Hello $a3[fname],\nhere is login information for $_SERVER[HTTP_HOST]\n\nUsername: $a3[uname]\nPassword: $a3[upass]\n\nKeep this information in a secure place.\n\nThanks for your registration.\nWe believe you will find a job at \n http://$_SERVER[HTTP_HOST]";

		$headers = "MIME-Version: 1.0\n"; 
		$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
		$headers .= "Content-Transfer-Encoding: 8bit\n"; 
		$headers .= "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>\n"; 
		$headers .= "X-Priority: 1\n"; 
		$headers .= "X-MSMail-Priority: High\n"; 
		$headers .= "X-Mailer: PHP/" . phpversion()."\n"; 

		mail($to, $subject, $message_body, $headers);
		header("location:jobseekers/thanks.php");
		exit();
	}

}

header("location:index.php");

?>